package com.person.mall.controller;

import com.mysql.cj.Session;
import com.person.mall.consts.MallConst;
import com.person.mall.form.ShippingForm;
import com.person.mall.pojo.User;
import com.person.mall.service.IShippingService;
import com.person.mall.service.Impl.ShippingService;
import com.person.mall.vo.ResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import java.util.Map;

/**
 * @author 最酷的桃儿wjc
 * * @date 2022/5/23
 */
@RestController
public class ShippingController {
    @Autowired
    private IShippingService iShippingService;

    /**
     * 添加收货地址
     * @param shippingForm
     * @param session
     * @return
     */
    @PostMapping("/shippings")
    public ResponseVo addShippings(@Valid @RequestBody ShippingForm shippingForm, HttpSession session){
        User user = (User) session.getAttribute(MallConst.CURRENT_USER);
        return iShippingService.addShipping(user.getId(),shippingForm);
    }

    /**
     * 删除购物车信息
     * @param shippingId
     * @param session
     * @return
     */
    @DeleteMapping("shippings/{shippingId}")
    public ResponseVo delShippings(@PathVariable Integer shippingId,HttpSession session){
        User user = (User) session.getAttribute(MallConst.CURRENT_USER);
        return iShippingService.delShipping(user.getId(),shippingId);
    }


    /**
     * 更新购物车信息
     * @param shippingForm
     * @param shippingId
     * @return
     */
    @PutMapping("shippings/{shippingId}")
    public ResponseVo updateShipping(@Valid @RequestBody ShippingForm shippingForm,@PathVariable Integer shippingId,HttpSession session){
        User user = (User) session.getAttribute(MallConst.CURRENT_USER);
        return iShippingService.updateShipping(user.getId(),shippingId,shippingForm);
    }



}
